#!/bin/bash
# description:　Rsync war file
# version:	1.0
# author:	zhangyanbin
# contact:	yanbin_zhang@foxitsoftware.com
#
. /etc/init.d/functions.sh

# "master" or "develop"
usage()
 {
	echo "usage: `basename $0` \$1"
	echo "\$1 :specfify a branch (develop/master)"
}

if [ -z $1 ]; then
#echo "ERROR: please specfify a branch (develop/master)"
	usage
	exit -1
fi

BRANCH=$1

if [ "$DL_SERVER" = "" ]; then
error_and_log "Download server url is empty. Please check $DL_SERVER_FILE_NAME"
exit -1;
else
warning_and_log "Download Server Url is: $DL_SERVER"
fi

GENERIC_SRC=smx@${DL_SERVER}:/opt/www/ops30.sumilux.com

echo "--> Begin to download worker war file, branch = $BRANCH "
 if [ ! -e /opt/pcs-server/pcs-server ]; then
mkdir -p /opt/pcs-server/pcs-server
 fi
WAR_FILE_SRC=smx@${DL_SERVER}:/opt/www/${DL_SERVER}/pcs-server/latest/${BRANCH}/
WAR_FILE_DST=/opt/pcs-server/pcs-server/
rsync ${RSYNC_OPTS} -e "${RSH_OPTS}" ${WAR_FILE_SRC} ${WAR_FILE_DST} 1>/dev/null


echo "--> Begin to download so file,branch = $BRANCH "
 if [ ! -e /usr/share/tomcat/latest/temp/v2/ ]; then
mkdir -p /usr/share/tomcat/latest/temp/v2/
 fi
SOFILES_SRC=smx@${DL_SERVER}:/opt/www/${DL_SERVER}/sofiles_64/latest/${BRANCH}/
rsync ${RSYNC_OPTS} -e "${RSH_OPTS}" ${SOFILES_SRC} /tmp/sofiles_64/ 1>/dev/null
cp /tmp/sofiles_64/libPdfEngine_x64.so /usr/share/tomcat/latest/temp/v2/libPdfEngine_x64.so

echo "--> download_files.sh finished in ${SECONDS}s"